ALL := info.out order_pizza.out categorize.out bermuda.out geo2json.out \
	tracks.out monte.out card_counter.out scuba.out fish.out 
sources := $(wildcard *.c)

# all
all: $(ALL)
.PHONY: all

# chap 05
scuba.out: scuba.o
	gcc -o scuba.out scuba.o

fish.out: fish.o
	gcc -o fish.out fish.o

# chap 04
info.out: info.o
	gcc -std=c99 -o info.out info.o

# chao 3
order_pizza.out: order_pizza.o
	gcc -o order_pizza.out order_pizza.c

categorize.out: categorize.o
	gcc -o categorize.out categorize.o

bermuda.out: bermuda.o geo2json.out
	gcc -o bermuda.out bermuda.o

geo2json.out: geo2json.o
	gcc -o geo2json.out geo2json.o

# chap 2.5
tracks.out: tracks.o find_track.o
	gcc -o tracks.out tracks.o find_track.o

# chap 2
monte.out: monte.o
	gcc -o monte.out monte.o

# chap 1
card_counter.out: card_counter.o
	gcc -o card_counter.out card_counter.o

# .d generation
%.d: %.c
	@set -e; rm -f $@; \
	 gcc -MM $< > $@.$$$$; \
	 sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
	 rm -f $@.$$$$

# include all the .d files
include $(sources:.c=.d)

# clean action
.PHONY: clean cleanOut cleanObj cleanDep
clean: cleanDep cleanObj cleanOut

cleanDep:
	-rm *.d
cleanObj:
	-rm *.o
cleanOut:
	-rm *.out

